#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File selenium_client
 * Created by leixu on 2017/9/18
 * IDE PyCharm
'''

import asyncio


def async_script_runner(f_script, rule_number, param_deliver):
    async def begin_job():
        try:
            f_script.build_crawler(param_deliver)
            return await f_script.async_crawl_rule(rule_number)
        except Exception as e:
            return str(e)
            import traceback
            traceback.print_exc()

    loop = asyncio.new_event_loop()
    result = loop.run_until_complete(begin_job())
    loop.close()
    return result


def this_process_script_runner(f_script, rule_number, param_deliver):
    def begin_job():
        f_script.build_crawler(param_deliver)
        return f_script.crawl_rule(rule_number)

    return begin_job()
